package com.base.cn.platform.os.controller.user.academic;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.manage.user.user.CusUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 学员学业（专业接口）Controller
 *
 * @author s.li
 * @create 2018-08-30-9:42
 */
@RestController
@RequestMapping("/api/user/")
public class ApiUserAcademicController extends ApiBaseController {

    @Autowired
    private CusUserService cusUserService;

    /**
     * 获取学业信息
     * @param userId 用户ID
     * @return Map<String,Object>
     */
    @RequestMapping("/myAcademic")
    public Map<String,Object> myAcademic(@RequestParam("userId")BigDecimal userId){
        Map<String,List<Map<String,Object>>> subjectList = cusUserService.findUserAcademic(userId);
        return ResultUtil.SUCCESS(subjectList);
    }

    /**
     * 获取用户可以添加的专业列表
     * @param userId 用户ID
     * @return Map<String,Object>
     */
    @RequestMapping("/querySubjectList")
    public Map<String,Object> getSubjectParent(@RequestParam(value = "userId") BigDecimal userId){
        return cusUserService.findUserSureSelectParentList(userId);
    }

    /**
     * 专业下的所有科⽬
     * @param parentIds 专业ID串
     * @return Map<String,Object>
     */
    @RequestMapping("/querySubjectByParentIds")
    public Map<String,Object> querySubjectByParentIds(@RequestParam("userId") BigDecimal userId,
                                                      @RequestParam("parentIds") String parentIds){
        return cusUserService.findUserSureSelectChildList(userId,parentIds);
    }

    /**
     * 添加专业和科目
     * @param userId 用户ID
     * @param subjectIds 专业科目ID串，如果：1,2
     * @return Map<String,Object>
     */
    @RequestMapping("/userAddSubject")
    public Map<String,Object> userAddSubject(@RequestParam("userId") BigDecimal userId,
                                             @RequestParam("subjectIds") String subjectIds){
        return cusUserService.updateUserNaturalSubjectIds(userId, subjectIds);
    }
}
